﻿/*
 * DataAccessAbstract.cs
 * 
 * author Trần Thái Bình
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Collections;

namespace DataAccessLayer
{
    /// <summary>
    /// Lớp DataAccessAbstract làm lớp cơ sở.
    /// </summary>
    public class DataAccessAbstract
    {
        protected OleDbConnection _connection;
        protected OleDbCommand _command;
        protected OleDbDataAdapter _adapter;
        protected OleDbDataReader _reader;
        protected string _sqlString;

        public DataAccessAbstract()
        {
            
        }
        
        /// <summary>
        /// Tạo kết nối với cơ sở dữ liệu Access.
        /// </summary>
        /// <returns>OleDbConnection</returns>
        public OleDbConnection ConnectionData()
        {
            OleDbConnection connection;
            string DBFilePath = "";
            for (int i = 0; i < Application.StartupPath.Length - 14; i++) // 21 la "\DataAccessLayer\bin\Debug"
            {
                DBFilePath += Application.StartupPath[i].ToString();
            }
            DBFilePath += @"\DataAccess\QuanLyGiaiVoDichQuocGia.accdb";
            string stringConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + DBFilePath;
            connection = new OleDbConnection(stringConnection);
            connection.Open();

            return connection;
        }
        
    }
}
